package util;
//201902104061徐中堂
import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.interfaces.DecodedJWT;

import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;

public class JWTHelper {
    public static final String SING = "!@234%U?H23";
    public static String getToken(Map<String,String> map){
        Calendar instance = Calendar.getInstance();
        instance.add(Calendar.DATE,1);
        HashMap<String,Object> map1 = new HashMap<>();
       String token = JWT.create().withHeader(map1)//头信息
                .withClaim("username",map.get("username"))//payload荷载实际的信息
                .withClaim("password",map.get("password"))
                .withExpiresAt(instance.getTime())//设置令牌过期时间
                .sign(Algorithm.HMAC256(SING));//签名头+荷载+密钥 组合之后加密得到
        return token;
    }
    public static DecodedJWT verify(String token){
        return JWT.require(Algorithm.HMAC256(SING)).build().verify(token);
    }
}
